import {Dep} from './dep'
import {queueWatcher} from "./scheduler";
let id = 0
export class Watcher {
  constructor(vm, fn, cb, options) {
    this.id = id++
    this.vm = vm
    this.fn = fn
    this.cb = cb
    this.depsId = new Set()
    this.deps = []
    this.options = options
    this.getter = fn
    this.get()
  }
  get() {
    Dep.target = this
    this.getter()
    Dep.target = null
  }
  addDep(dep) {
    if (!this.depsId.has(dep.id)) {
      this.depsId.add(dep.id)
      this.deps.push(dep)
      dep.addSub(this)
    }
  }
  update(){
    console.log('准备update')
    queueWatcher(this)
  }
}
